package chen.web.back.client;

import com.extjs.gxt.ui.client.widget.HtmlContainer;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.Cookies;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.Window;

public class TopArea extends LayoutContainer implements ValueChangeHandler<String>{

	@Override
	protected void onRender(Element parent, int index) {
		// TODO Auto-generated method stub
		super.onRender(parent, index);
		String logout = "<a href=\"#logout\">退出</a>";
		HtmlContainer htmlContainer = new HtmlContainer("<b>后台管理系统<b/>" + logout);
		add(htmlContainer);
		
		History.addValueChangeHandler(this);
		History.fireCurrentHistoryState();
	}

	@Override
	public void onValueChange(ValueChangeEvent<String> event) {
		// TODO Auto-generated method stub
		if("logout".equals(event.getValue())){
			Cookies.removeCookie("login");
			Window.Location.assign("#");
			Window.Location.reload();
		}
	}

}
